/* 
 * File:   epoll_loop.cpp
 * Author: 周晓场
 * Description: epoll_loop线程的实现
 */
#include "server.h"

void*
epoll_loop(void* arg){

	pthread_detach(pthread_self());

	// 开启多线程支持
	if (evthread_use_pthreads() < 0)
	  cout << "use pthreads error" << endl;
	//#ifndef EVTHREAD_USE_PTHREADS_IMPLEMENTED
	//#endif
	
	// 获得event_base
	base[(int)arg] = event_base_new();
	if (NULL == base[(int)arg]){
		cout << "create event_base error" << endl;
		exit(1);
	}

	event_base_loop(base[(int)arg], EVLOOP_NO_EXIT_ON_EMPTY);

	event_base_free(base[(int)arg]);

	return NULL;
}

void
thread_make(int c){
	pthread_t tid;
	pthread_create(&tid, NULL, &epoll_loop, (void*)c);
	return;
}
